<template>
	<view class="page">
		<headnav leftText="确认订单"></headnav>
		<scroll-view scroll-y="true"  class="scroll-v pageScroll">
		  <view class="pageBox">
			 <view class="block dls">
				 <view class="dl">
					 <view class="dt">配送方式</view>
					 <view class="dd">
					      <text v-if="order.delivery_type == 1">配送到校</text>
						  <text v-if="order.delivery_type == 2">配送个人</text>
					 </view>
				 </view>
				 <view class="dl">
					 <view class="dt">发货时间</view>
					 <view class="dd">{{order.delivery_date}}</view>
				 </view>
				 <view class="dl">
						 <view class="dt">付费方式</view>
						 <view class="dd">
							 <text v-if="order.payway == 1">在线</text>
							 <text v-if="order.payway == 2">线下</text>
						 </view>
				 </view>
				 <view class="dl">
						 <view class="dt">学生姓名</view>
						 <view class="dd">{{user.student_name}}</view>
				 </view>
				 <view class="dl">
						 <view class="dt">手机号</view>
						 <view class="dd">{{user.student_mobile}}</view>
				 </view>
			 </view>
			 <view class="block dls">
				 <view class="dl">
					 <view class="dt">学校</view>
					 <view class="dd">{{user.school_name}}</view>
				 </view>
				 <view class="dl">
					 <view class="dt">学院</view>
					 <view class="dd">{{user.school_college_name}}</view>
				 </view>
				 <view class="dl">
						 <view class="dt">年级</view>
						 <view class="dd">{{user.start_year}}</view>
				 </view>
				 <view class="dl">
						 <view class="dt">班级</view>
						 <view class="dd">{{user.class_name}}</view>
				 </view>
			 </view>
			 <view class="block dls-h">
				 <view class="good-item" v-for="(item,index) in goods" :key="index">
					 <view class="dls-h-t">
					 		{{item.name}}	 
					 </view> 
					 <view class="h-t-info">
					 	 <view>× <text>{{item.num}}</text></view>
						 <view class="h-t-r">
							 <text v-if="type == 1">【预付款】</text> ¥ {{item.prepayment}}
						 </view>						  
					 </view>
				 </view>
			 </view>
		  </view>
		</scroll-view>
		<view class="totelBotttom">
			<!-- <view class="checkAll">
				<image src="/static/img/checkIcon.png" class="checkIcon" mode=""></image>
				<text>全选</text>
			</view> -->
			<!-- <view class="tot-m">
				合计: <text class="rmb">¥</text><text class="price">11.00</text>
			</view> -->
			<view class="tot-m2 tot-m4">
				<view class="tot-pr" :class="{'paddingTop':type == 0}">
					<text v-if="type == 1">【预付款】</text> 合计: <text class="rmb">¥</text><text class="price">{{totalPrice}}</text>
				</view>
				<view class="warn" v-show="type == 1">
					预付款不可退
				</view>
			</view>
			<view class="btn" @tap="topay">
				结算
			</view>
		</view>
	</view>
</template>
<script>
	import { creatOrder } from '@/api/goods.js'
	import Cache  from '@/util/cache.js'
	import { payCreatOrder,  payformOrder} from '@/api/pay.js'
	export default {
		data() { 
			return {
				order:{},
				open:true,
				goods:[],
				type:1,
				totalPrice:0,
				swiper:{
					current:0,
					mode:'round',
					dotsStyles:{
						backgroundColor: '#a7c8fa',
						border: '1px #a7c8fa solid',
						color: '#fff',
						bottom:"-10rpx",
						selectedBackgroundColor: '#3c84f4',
						selectedBorder: '1px #3c84f4 solid'
					}
				},
				
			}
		},
		onLoad() {
			// console.log(this.user);
			this.order = Cache.get('order') ? Cache.get('order') : {};
			this.type = this.order.is_presale;
			this.goods = this.order.goods;
		    this.post_data = this.order.post_data;
			//console.log(this.order);
			// Cache.set('order','')
			// console.log(this.goods);
			this.reudcePrice();
			// console.log(this.order);
		},
		methods: {
			topay() {
				payCreatOrder(this.post_data);
			},
			togleOpen() {
				this.open = !this.open;
			},
			gochangeSchool() {
				uni.navigateTo({
					url:'/pages/changeSchool/changeSchool'
				})
			},
			countChange() {
				
			},
			reudcePrice(){
				const prices = this.goods.map(item => item.prepayment);
									//console.log(prices);
				const sum = prices.reduce((acc,  curr) => Number(acc) + Number(curr), 0);
				this.totalPrice = sum.toFixed(2);
			},
			goComfirm() {
				this.$Router.push('/pages/payOrder/payOrder')
			},
			change(e) {
				this.swiper.current = e.detail.current;
			}
		}
	}
</script>

<style lang="scss">
	@import "@/static/css/detial.scss";
	.page {
		background-color: #f5f8fa;
		width: 100%;
		height: 100%;
	}
	.pageBox {
		padding-bottom: 130rpx;
	}
	.dls-h {
		background-color: #fff;
		padding: 37rpx 37rpx 27rpx;
		border-radius: 26rpx;
		margin-bottom: 20rpx;
		.good-item {
			margin-bottom: 10rpx;
		}
		.dls-h-t {
		  font-size: 28rpx;
		  margin-bottom: 20rpx;
		}
		.h-t-info {
			display: flex;
			justify-content: space-between;
			.h-t-r {
				color:#ff4f4f;
			}
		}
	}
	.dls{
		background-color: #fff;
		border-radius: 26rpx;
	    padding:  0 40rpx;
		margin-bottom: 30rpx;
		.dl {
			border-bottom: 1px solid #f5f5f5;
			display: flex;
			justify-content: space-between;
			&:last-of-type {
				border-bottom: none;
			}
			.dt, .dd {
				height: 100rpx;
				line-height: 100rpx;
				font-size: 30rpx;
			}
		}
	}
	
</style>
